package com.liandu.dao;

import com.liandu.common.PageInfo;
import com.liandu.common.parent.ParentDao;
import com.liandu.entity.WeighInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Set;

public interface WeighInfoDao extends ParentDao<WeighInfo,Long> {

    List<WeighInfo> findAllByTraHashIsNullOrderByInsertDateTimeDesc();
    Page<WeighInfo> findAllByTraHashIsNullOrderByInsertDateTimeDesc(Pageable pageable);

    @Query(nativeQuery = true,value = "select * from weighinfo a join ecrinfo b on a.uploadDevice = b.ecrID" +
            " join busiinfo c on b.busiId = c.busiInfoID " +
            "where a.insertDateTime between ?2 and ?3" +
            " and if(?1 is null,1,traceCode like ?1) and if(?4 is null,1,c.busiName like concat('%',?4,'%'))" +
            " order by a.insertDateTime desc ")
    Page<WeighInfo> findAllWeightInfo(String traceCode, Date startDate, Date endDate, String busiName, Pageable pageable);

    List<WeighInfo> findAllByUploadDeviceIn(Set<String> ids);
}
